package company.folder.beans;

import company.abstractClasses.AbstractCompanyAdquiredProfileCapableFilterList;
import company.folder.qualifiers.SeeAllProfilesEvent;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Observes;
import comparators.CompanyAdquiredProfileCapableComparator;
import entities.CompanyAdquiredProfile;
import facades.AbstractFacade;
import javax.enterprise.event.TransactionPhase;
import predicates.CandidateCapableIsValidPredicate;
import predicates.CompanyAdquiredProfileCapableSearchCapablePredicate;
import util.filter.CollectionsFilter;

/**
 *
 * @author damfercer
 */
@Named
@SessionScoped
public class NewViewAllProfilesBean extends AbstractCompanyAdquiredProfileCapableFilterList<CompanyAdquiredProfile, AbstractFacade<CompanyAdquiredProfile>, CompanyAdquiredProfileCapableComparator<CompanyAdquiredProfile,CompanyAdquiredProfileCapableSearchCapablePredicate<CompanyAdquiredProfile>>, CompanyAdquiredProfileCapableSearchCapablePredicate<CompanyAdquiredProfile>> implements Serializable {
    
    public void onViewAllProfiles(@Observes(during = TransactionPhase.AFTER_SUCCESS) @SeeAllProfilesEvent Integer i){
        this.reinitFilter();
        setChosenEntity(null);
        initCandidates();
    }
        
    @Override
    public String redirectToViewEntity(){
        return "/views/company/folder/ViewCandidateView?faces-redirect=true";
    }    

    @Override
    public void initCandidates(){
        setBaseEntityList(new ArrayList<CompanyAdquiredProfile>(CollectionsFilter.filterOnNewCollection(getCompany().getCompanyAdquiredProfileList(), new CandidateCapableIsValidPredicate<CompanyAdquiredProfile>())));
        setEntityList(new ArrayList<CompanyAdquiredProfile>(getBaseEntityList()));
        if(getPredicate()!=null){
            filterFromBaseList();
            sort();
        }
    }

}
